package cn.edu360.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu360.pojo.User;
import cn.edu360.service.UserService;

@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/user/genCode")
	@ResponseBody
	public boolean genVerifyCode(String countryCode,String phoneNum) {
		boolean flag = userService.sendMsg(countryCode,phoneNum);
		return false;
	}
	
	@RequestMapping("/user/verify")
	@ResponseBody
	public boolean verify (String phoneNum,String verifyCode) {
		return userService.verify(phoneNum,verifyCode);	
	}
	
	@RequestMapping("/user/register")
	@ResponseBody
	public boolean reg (@RequestBody User user) {
		
		boolean flag = true;
		//调用service,将用户的数据保存起来
		
		 try {
			userService.register(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			flag = false;
		}
		return flag;	
	}
	
	@RequestMapping("/user/deposite")
	@ResponseBody
	public boolean deposite(@RequestBody User user) {
		boolean flag = true; 
		try {
			userService.update(user);
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		 return flag;
	}
	
	@RequestMapping("/user/identify")
	@ResponseBody
	public boolean identify(@RequestBody User user) {
		boolean flag = true;
		try {
			userService.update(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
	
}
